<template>

    <div id="aduser">
        <g-admin></g-admin>
        <h1>编辑文章</h1>
        <el-table :data="tableData" border="true" style="width: 100%">
            <el-table-column prop="articleID" label="文章编号" width="150px"></el-table-column>
            <el-table-column prop="title" label="文章题目" width="150px"></el-table-column>
            <el-table-column label="管理员姓名" prop="adminName"></el-table-column>
            <el-table-column label="内容" prop="content"></el-table-column>
            <el-table-column label="发布时间" prop="time"></el-table-column>
            <el-table-column label="点赞数" prop="goodNum"></el-table-column>
            <el-table-column label="操作" width="180px">
                <template slot-scope="scope">
                    <!-- 修改按钮 -->
                    <el-button @click="edit(scope.row['articleID'])" type="primary" size="small">修改</el-button>
                    <el-button @click="deleteArticle(scope.$index)" type="danger" size="small">删除</el-button>

                </template>
            </el-table-column>
        </el-table>

    </div>

</template>

<script>
    import GAdmin from '../../components/gadmin/GAdmin';
    import axios from 'axios'
    export default {
        components:{
            GAdmin
        },
        data() {
            return {
                tableData:[{
                    articleId:'',
                    title:'',
                    adminName:'',
                    content:'',
                    time:'',
                    goodNum:''
                }
                ]
            }
        },
        created() {

            this.request({
                url:'http://127.0.0.1:8080/article/find'
            }).then(res=>{
                this.tableData = res.data;
                console.log(this.tableData);
            }).catch(err=>{
                console.log(err);
            });

        },
        mounted(){
            document.querySelector('.tabbar').setAttribute('style','display:none');
            document.querySelector('.gfooter').setAttribute('style','display:none');
        },
        methods: {
            edit(articleId){
                this.$router.push({
                    path:'/admin/admin/adarticleupdate',
                    query:{
                        articleID:articleId
                    }
                }).catch(error=>error)

            },
            deleteArticle(index){
                let url='http://localhost:8080/article/removearticle';
                axios.post(url, this.tableData[index]).then(
                    res=>{
                        alert("删除成功！");
                        location.reload(true);
                        console.log(res.data);
                    }).catch(err=>{
                        console.log(err);
                    }
                )
            },
            getArticleList(){

            }
        }
    }
</script>

<style scoped>

    #aduser{
        width: 90%;
        margin-left: 10%;
        margin-top: 40px;
    }
</style>